import {
	BASEURL
} from "./config.js"
const request = (method, url, data = {}) => {
	let token = uni.getStorageSync("token")
	let companyid = uni.getStorageSync("companyid")
	if (!token) {
		uni.navigateTo({
			url: '/pages/login/login'
		})
	}

	//异步请求, 

	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中...',
		})
		
		uni.request({
			url: BASEURL + url,
			data: data,
			method: method,
			header: {
				'Content-Type': 'application/json;charset=UTF-8',
				'token': token, //自定义请求头信息,
				'companyid': companyid
			},
			success: (res) => {

				resolve(res.data)
				uni.hideLoading()

			},
			fail: (err) => {
				reject(err)
				uni.hideLoading()
			}
		});

	})

}
const get = (url, data) => {

	return request("GET", url, data)
}
const post = (url, data) => {

	return request("POST", url, data)
}
export {
	get,
	post
}
